package com.youbug.kefu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youbug.kefu.entity.Chat;
import com.youbug.kefu.entity.User;
import com.youbug.kefu.mapper.ChatMapper;
import com.youbug.kefu.service.IChatService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youbug.kefu.vo.ChatVo;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 会话表 服务实现类
 * </p>
 *
 * @author youbug
 * @since 2023-01-07
 */
@Service
public class ChatServiceImpl extends ServiceImpl<ChatMapper, Chat> implements IChatService {

    @Override
    public IPage<Chat> getChatPage(ChatVo chatVo) {

        Page<Chat> page = new Page<>();

        page.setCurrent(chatVo.getCurrentPage());

        page.setSize(chatVo.getPageSize());

        QueryWrapper<Chat> wrapper = new QueryWrapper<>();

        if(!ObjectUtils.isEmpty(chatVo.getStartTime())){

            wrapper.gt("create_time", chatVo.getStartTime());
        }

        if(!ObjectUtils.isEmpty(chatVo.getEndTime())){

            wrapper.lt("create_time", chatVo.getEndTime());
        }

        if(!ObjectUtils.isEmpty(chatVo.getAgentName())){

            wrapper.like("agent_name", chatVo.getAgentName());
        }

        wrapper.orderByDesc("create_time");

        Page<Chat> result = this.page(page, wrapper);

        return result;
    }
}
